<template>
    <div>
        <el-row :gutter="20">
            <el-col :span="20" >
                <div style="margin-left:20px;font-weight: bolder;color:#666">活动详情</div>
            </el-col>

            <el-col :span="4">
                <el-button @click="go">返回列表</el-button>
            </el-col>
        </el-row>

        <el-form  ref="form" :model="form" label-position="labelPosition" label-width="100px">
            <el-form-item label="活动标题" >
                <!--<el-input style="width:300px" v-model="form.title" readonly></el-input>-->
                {{form.title}}
            </el-form-item>
            <el-form-item label="活动说明" >
                <!--<el-input-->
                        <!--type="textarea"-->
                        <!--:rows="3"-->
                        <!--placeholder="活动说明"-->
                        <!--v-model="form.desc" style="width:300px"readonly>-->
                <!--</el-input>-->
                <div style="max-width:500px">
                    {{form.desc}}
                </div>

            </el-form-item>
            <el-form-item label="开始时间" >
                <!--<div class="block">-->
                    <!--<el-date-picker-->
                            <!--v-model="form.start_time"-->
                            <!--type="date"-->
                            <!--placeholder="选择日期"-->
                            <!--:picker-options="pickerOptions0" readonly>-->
                    <!--</el-date-picker>-->
                <!--</div>-->
                {{form.start_time}}
            </el-form-item>
            <el-form-item label="截止时间" >
                <!--<div class="block">-->
                    <!--<el-date-picker-->
                            <!--v-model="form.end_time"-->
                            <!--type="date"-->
                            <!--placeholder="选择日期"-->
                            <!--:picker-options="pickerOptions0" readonly>-->
                    <!--</el-date-picker>-->
                <!--</div>-->
                {{form.end_time}}
            </el-form-item>
        </el-form>
        <div style="margin-bottom:20px;margin-left:45px;font-size:16px;color:#666">缩略图</div>
        <div style="margin-left:100px;margin-bottom:100px">
            <el-upload
                    class="avatar-uploader"
                    :action=fileUploadAction
                    :show-file-list="false"
                     readonly="readonly" disabled>
                <img v-if="imageUrl" :src=imageUrl class="avatar">
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                <!--<div slot="tip" class="el-upload__tip">（支持png/jpg格式，文件大小不能超过3M）</div>-->
            </el-upload>
        </div>
        <el-form  label-position="labelPosition" label-width="100px">
            <el-form-item label="活动内容" >
               <div v-html="form.content" style="max-width:80%">
                   {{form.content}}
               </div>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
    import _http from '@/components/common/http.vue'
    import _param from '@/components/common/param.vue'
//    import '@/assets/ueditor/ueditor.config.js'
//    import '@/assets/ueditor/ueditor.all.min.js'
//    import '@/assets/ueditor/ueditor.parse.min.js'
//    import '@/assets/ueditor/lang/zh-cn/zh-cn.js'
    export default {
        data() {
            return {
                imageUrl:'',
                id:'',
                apiPort:{
///                    发布内容接口
                    fabuList:"activity/addActivity",
//                    回显接口
                    getBack:"activity/toeditActivity",
//                    编辑上传接口
                    editUp:'activity/editActivity'
                },
                editor:null,
                fileUploadAction:_param.param.fileUploadUrl,
                userid:'',
                textarea:'',
                form:{
                    title:'',
                    desc:'',
                    start_time:'',
                    end_time:'',
                    picture_url:'',
                    content:'',
                    userid:''
                },
                activeName: 'second',
                labelPosition: 'right',
                dialogImageUrl: '',
                dialogVisible: false,
                value1: '',
            };
        },
        mounted(){
            console.log(this.$route.query.info)
            this.id = this.$route.query.info
            this.userid=localStorage.getItem('userId')
            this.form.userid = localStorage.getItem('userId')
            var that = this
//            this.editor = UE.getEditor('editor');
                this.getBack(this.id)
        },

        methods: {
            limit(file,fileList){
                console.log(file)
                console.log(fileList)
            },
//            发布提交
            submit(){

                if(this.id!=1){
                    this.editActive()
                }else{
                    this.addActive()
                }
            },

            editActive(){
                console.log(this.form.start_time)
                this.form.content=this.editor.getContent()
                var that = this
                var params = that.querystring.stringify(this.form)
                _http.axiosRequest(that,that.apiPort.editUp,params,(res)=>{
                    if(res.data.code==100){
                    that.$message({
                        message: '活动编辑成功',
                        type: 'success'
                    });
                }else{
                    that.$message({
                        message:res.data.msg,
                        type: 'warning'
                    });
                }
            })
            },
//            获取回显内容
            getBack(id){
                var that = this
                var params = that.querystring.stringify({'id':id,'userid':this.form.userid})
                _http.axiosRequest(that,that.apiPort.getBack,params,(res)=>{
                    that.form.title = res.data.data.title
                that.form.desc = res.data.data.desc
                that.form.content = res.data.data.content
//                that.editor.setContent(res.data.data.content)
                that.form.start_time = res.data.data.start_time
                that.form.end_time = res.data.data.end_time
                that.dialogImageUrl=res.data.data.picture_url
                console.log(that.dialogImageUrl)
//                    还有缩略图地址
                    that.imageUrl = res.data.data.picture_url
            })
            },
            pickerOptions0: {
                disabledDate(time) {
                    return time.getTime() < Date.now() - 8.64e7;
                }
            },
            handleClick(tab, event) {
                console.log(tab, event);
            },
            go(){
                this.id=''
                this.$router.go(-1)
            },
            handleRemove(file, fileList) {
                console.log(file, fileList);
            },

        }
    };
</script>